import { userApi } from './api'
import axios from 'axios'

export default {
  login(data) {
    return axios({
      method: 'post',
      url: userApi.loginAuthUrl(),
      data: data,
      headers: { 'X-Requested-With': 'XMLHttpRequest', 'Content-Type': 'application/x-www-form-urlencoded'}
    })
  },
  userInfo() {
    return axios({
      method: 'get',
      url: userApi.userInfoUrl(),
      withCredentials: true
    })
  },
  loginOut() {
    return axios({
      method: 'get',
      url: userApi.loginOutUrl(),
      withCredentials: true
    })
  },
  userDetails() {
    return axios({
      method: 'get',
      url: userApi.userDetailsUrl(),
      withCredentials: true
    })
  },
  update(userId, user) {
    return axios({
      method: 'put',
      url: userApi.updateDetailsUrl(userId),
      data: user,
      withCredentials: true
    })
  },
  updatePassword(changePwdDto) {
    return axios({
      method: 'put',
      url: userApi.updatePasswordUrl() ,
      data: changePwdDto,
      withCredentials: true
    })
  }
}
